Ext.extend(app.module,{
    currentFormValues: {},
    init: function(){
        var main = this;
        //用于列表
        this.ds = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({url:'score/getMark.do'}),
            reader: new Ext.data.JsonReader({
                totalProperty: 'total',
                root: 'rows'
            },[
                {name:'stuid'},
                {name:'paperid'},
                {name:'papername'},
                {name:'kemuname'},
                {name:'phone'},
                {name:'cardid'},
                {name:'username'},
                {name:'number'},
                {name:'mark'}
            ])
        });
        // 翻页排序时带上查询条件
        this.ds.on('beforeload', function() {
            this.baseParams = {
                cardid : Ext.getCmp('querydelayCardid').getValue(),
                number : Ext.getCmp('querydelayNumber').getValue(),
                username : Ext.getCmp('querydelayUserName').getValue(),
                paperId: Ext.getCmp('querydelayPaper').getValue()
            };
        });

        var delay_pagesize_combo = new Ext.form.ComboBox( {       //设置分页栏的每页记录数选择
            name : 'pagesize',
            hiddenName : 'pagesize',
            typeAhead : true,
            triggerAction : 'all',
            lazyRender : true,
            mode : 'local',
            store : new Ext.data.ArrayStore(
                {
                    fields : [ 'value', 'text' ],
                    data : [ [ 100, '100条/页' ], [ 200, '200条/页' ],
                        [ 300, '300条/页' ], [ 500, '500条/页' ],
                        [ 800, '800条/页' ], [ 1000, '1000条/页' ] ]
                }),
            valueField : 'value',
            displayField : 'text',
            value : '20',
            editable : false,
            width : 85
        });
        var number = parseInt(delay_pagesize_combo.getValue());

        delay_pagesize_combo.on("select", function(comboBox) {
            var bbar = Ext.getCmp('delaybbar');
            bbar.pageSize = parseInt(comboBox.getValue());
            number = parseInt(comboBox.getValue());
            main.ds.reload( {
                params : {
                    start : 0,
                    limit : bbar.pageSize,
                    cardid : Ext.getCmp('querydelayCardid').getValue(),
                    number : Ext.getCmp('querydelayNumber').getValue(),
                    username : Ext.getCmp('querydelayUserName').getValue(),
                    paperId: Ext.getCmp('querydelayPaper').getValue()
                }
            });
        });
        //试卷选择的store
        var paperStore = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({url:'paper/getNotEndPaper.do'}),
            reader: new Ext.data.JsonReader({
                root: 'rows',
                idProperty: 'id'
            },[
                {name:'id'},
                {name:'name'}
            ])
        });
        //试卷选择的下拉框
        comboPaper = new Ext.form.ComboBox({
            store: paperStore,
            editable: false,
            emptyText: '请选择试卷...',
            allowBlank: false,
            mode: 'remote',
            hiddenName : 'paperid',
            typeAhead : true,
            triggerAction : 'all',
            displayField: 'name',
            valueField: 'id',
            fieldLabel: '关联试卷'
        });

        comboPaper.on("select", function(comboBox) {
            Ext.getCmp('querydelayPaper').setValue(parseInt(comboBox.getValue()));
            main.ds.reload( {
                params : {
                    start : 0,
                    limit : bbar.pageSize
                }
            });
        });

        this.body = new Ext.grid.GridPanel({
            store: this.ds,
            region: 'center',
            loadMask: true,
            viewConfig:{
                forceFit:true
            },
            columns: [
                new Ext.grid.RowNumberer(),
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'stuid',
                    hidden: true
                },
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'paperid',
                    hidden: true
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'cardid',
                    header: '身份证',
                    width: 180
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'number',
                    header: '学号',
                    width: 100
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'username',
                    header: '姓名',
                    width: 80
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'phone',
                    header: '电话',
                    width: 120
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'papername',
                    header: '试卷名称',
                    width: 80
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'kemuname',
                    header: '科目',
                    width: 80
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'starttime',
                    header: '考试时间',
                    width: 100
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'kstime',
                    header: '时长(分钟)',
                    width: 50
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'firststarttime',
                    header: '首次登录时间',
                    width: 100
                },
                {
                    xtype: 'gridcolumn',
                    align: 'center',
                    dataIndex: 'delaytime',
                    header: '延时',
                    width: 50
                }
            ],
            tbar: {
                xtype: 'toolbar',
                items: [
                    {
                        text: '设置延时',
                        iconCls : 'btn-new',
                        scope: this,
                        handler: function(){
                            main.showDelayWindow();
                        }
                    },
                    '->',
                    {
                        xtype: 'textfield',
                        value: '',
                        id: 'querydelayPaper',
                        hidden: true
                    },
                    {
                        xtype: 'displayfield',
                        value: '查询条件：'
                    },
                    ' ',
                    {
                        xtype: 'displayfield',
                        value: '试卷：'
                    },
                    comboPaper,
                    ' ',
                    {
                        xtype: 'textfield',
                        id : 'querydelayCardid',
                        name : 'querydelayCardid',
                        emptyText : '请输入身份证号码',
                        enableKeyEvents : true,
                        listeners : {
                            specialkey : function(field, e) {
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                    main.query();
                                }
                            }
                        },
                        width : 120
                    },
                    ' ',
                    {
                        xtype: 'textfield',
                        id : 'querydelayNumber',
                        name : 'querydelayNumber',
                        emptyText : '请输入学号',
                        enableKeyEvents : true,
                        listeners : {
                            specialkey : function(field, e) {
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                    main.query();
                                }
                            }
                        },
                        width : 120
                    },
                    ' ',
                    {
                        xtype: 'textfield',
                        id : 'querydelayUserName',
                        name : 'querydelayUserName',
                        emptyText : '请输入姓名',
                        enableKeyEvents : true,
                        listeners : {
                            specialkey : function(field, e) {
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                    main.query();
                                }
                            }
                        },
                        width : 120
                    },
                    {
                        text : '查询',
                        iconCls : 'btn-search',
                        handler : function() {
                            main.query();
                        }
                    }

                ]
            },
            bbar: {
                id: 'delaybbar',
                xtype: 'paging',
                pageSize : number,
                store : this.ds,
                displayInfo : true,
                displayMsg : '显示{0}条到{1}条,共{2}条',
                emptyMsg : "没有符合条件的记录",
                items : [ '-', '&nbsp;&nbsp;', delay_pagesize_combo ]
            }
        });
        this.main.add(this.body);
        this.main.doLayout();
        this.ds.load({
            params: {
                start:0,
                limit:100
            }
        });
        this.render();
    },
    submit: function(){
        if (this.form.getForm().isValid()) {
            this.form.getForm().submit({
                waitTitle: '保存数据',
                waitMsg: '正在保存……',
                scope: this,
                method: 'post',
                params: '',
                submitEmptyText: false,     //禁止提交emptyText
                success: function(form, action) {
                    var info = action.result.info;
                    this.dlg.hide();
                    this.ds.reload();
                    Ext.Msg.alert('信息', info);
                },
                failure: function(form, action) {
                    var info = action.result.info;
                    this.dlg.hide();
                    this.ds.reload();
                    Ext.Msg.alert('提示', info);
                }
            });
        }
    },
    query: function(){
        this.ds.load({
            params : {
                start : 0,
                limit : Ext.getCmp('delaybbar').pageSize,
                cardid : Ext.getCmp('querydelayCardid').getValue(),
                number : Ext.getCmp('querydelayNumber').getValue(),
                username : Ext.getCmp('querydelayUserName').getValue(),
                paperId: Ext.getCmp('querydelayPaper').getValue()
            }
        });
    }
});
